[% setvar title Shell Style Redirection %]
<div id="archive-notice">
    <h3>This file is part of the Perl 6 Archive</h3>
    <p>To see what is currently happening visit <a href="http://www.perl6.org/">http://www.perl6.org/</a></p>
</div>
<div class='pod'>
<a name='TITLE'></a><h1>TITLE</h1>
<p>Shell Style Redirection</p>
<a name='VERSION'></a><h1>VERSION</h1>
<pre>  Maintainer: David Nicol &lt;<a href='mailto:perl6rfc@davidnicol.com'>perl6rfc@davidnicol.com</a>&gt;
  Date: 8 Aug 2000
  Last Modified: 5 Sep 2000
  Mailing List: <a href='mailto:perl6-language-io@perl.org'>perl6-language-io@perl.org</a>
  Number: 66
  Version: 2
  Status: Developing</pre>
<a name='ABSTRACT'></a><h1>ABSTRACT</h1>
<p>The <code>use redirect</code> pragma or a new <code>redirect</code> keyword is introduced
to allow redirection of streams of any kind into each other.</p>
<p>The keyword may not be really needed, as when does it make any
sense to do a lt or gt comparison with a file handle?</p>
<a name='SUMMARY'></a><h1>SUMMARY</h1>
<pre>	sub callfritz{

	   local STDIN &lt; $InputData;

	   local STDOUT &gt; PREVIOUSLY_OPENED_HANDLE;

	   eval `cat fritz.pl`;

	};</pre>
<p>is proposed as an alternative to doing the same thing
with a variety of open2 calls.</p>
<a name='DESCRIPTION'></a><h1>DESCRIPTION</h1>
<p>As an alternative to the Bourne shell style <code>open</code> syntax
described in `perldoc -f open`,  this
proposal overloads the less than and greater than operators
in order that subsequent statements,
particularly external routines that will be looking to
a file descriptor table for their file handles, will get from
and give to where we want them to.</p>
<p>The redirection is affected by the scoping operators like
any other variable which alters the situation.</p>
<p>It will also provide another way to capture STDERR from
within backticks.</p>
<pre>	sub ToolErrorsFirst{

		# place to hold the output
		my $tooloutput;	

		# place to hold the errors
		my $errors;

		# use redirect: very similar to shell redirection
		my use redirect STDOUT &gt; $tooloutput ;   

		# alternately, FILE &gt; $scalar is obviously a redirect
		# (if we accept the overload of &gt;)
		# so no additional keywords are required
		my  STDERR &gt; $errors ;   

		$tooloutput = `tool @_`;
		
		return $errors . $tooloutput;

	};</pre>
<p>Currently I do this kind of thing by using the
file system as temporary storage.</p>
<p>another use of the angle brackets would be as a single-character
print operator, similar to &lt;&lt; in C++ streams.</p>
<pre>	print $abc;
	print OUT $z;	# one way to do it

	&lt; $abc;
	OUT &lt; $z;	# another way to do it</pre>
<p>Left-angle could differ from <code>print</code> by returning the file handle,
instead of a success code, making C++ like constructions possible:</p>
<pre>	&lt; $this &lt; &quot;and&quot; &lt; $that; 	# same as print &quot;${this}and$that&quot;</pre>
<a name='IMPLEMENTATION'></a><h1>IMPLEMENTATION</h1>
<p>We need overloading based on type.  The &lt; operator will be
like <code>print</code> when there is a file handle on the left side,
it will be like assigning from &lt;FH&gt;  when there is a file handle on the
right, and it will be like the Bourne shell duplicate <code>open</code> when there
are file handles on both sides.</p>
<p>Setting up a way to trap the standard error from a forked process
and load it into a scalar -- will that be difficult?</p>
<a name='MIGRATION'></a><h1>MIGRATION</h1>
<p>Code that compares file handles, or compares file handles
with scalars, will break.</p>
<a name='CHANGES'></a><h1>CHANGES</h1>
<p>discussion of C++ and use of &lt; as a print operator</p>
<a name='REFERENCES'></a><h1>REFERENCES</h1>
<p>RFC 39: Perl should have a print operator</p>
<p>RFC 61: Interfaces for linking C objects into perlsubs</p>
</div>
